<?php

namespace app\merchant\controller;

use app\BaseController;
use app\merchant\service\OrderService;
use think\facade\Request;
use app\Response;

class Order extends BaseController
{
    public function orderIndex(){
        if(Request::method() == 'POST'){
            $m_uid = Request::param("m_uid");
            $post_num = Request::param("post_num","");
            $state = Request::param("state","");
            $start_time = Request::param("start_time","");
            $end_time = Request::param("end_time","");
            $page = Request::param("page",1);
            $num = Request::param("num",10);
            $res = OrderService::orderListService($m_uid,$page,$num,$post_num,$state,$start_time,$end_time);
            return $res;
        }
    }


    public function orderEdit(){
        if (Request::isPost()) {
            $oId = Request::param("id");
            $state = Request::param("state");//状态 1已录入 2已到网点  4已送达 6已结算
            $m_uid = Request::param("m_uid");
            $res = OrderService::orderEditService($oId,$m_uid,$state);
            return $res;
        }
    }

    /***
     * 订单状态批量变更
     */
    public function orderBatchEdit(){
        if (Request::isPost()) {
            $m_uid = Request::param("m_uid");
            $oIds = Request::param("ids");
            $state = Request::param("state");//状态 1已录入 2已到网点  4已送达 6已结算
            $res = OrderService::orderBatchEditService($m_uid,$oIds,$state);
            return $res;
        }
    }

    /***
     * 导入
     */
    public function orderImport(){
        $file = request()->file('excel_file');
        $m_uid = Request::param("m_uid");
        if ($file) {
            $res = OrderService::orderImportService($m_uid,$file);
            return $res;
        }else{
            return Response::wrapData(0,"请上传文件~!");
        }
    }

    /***
     * 订单导出
     */
    public function orderExcelExport(){
        $state = Request::param("state");//状态 1已录入 2已到网点  4已送达 6已结算
        $start_time = Request::param("start_time");
        $end_time = Request::param("end_time");
        $m_uid = Request::param("m_uid");
        $res = OrderService::orderExcelExportService($state,$start_time,$end_time,$m_uid);
        return $res;

    }
}